package net.xdclass.base_project;

import org.apache.activemq.command.ActiveMQQueue;
import org.apache.activemq.command.ActiveMQTopic;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.jms.annotation.EnableJms;
import org.springframework.jms.config.DefaultJmsListenerContainerFactory;
import org.springframework.jms.config.JmsListenerContainerFactory;

import javax.jms.ConnectionFactory;
import javax.jms.Queue;
import javax.jms.Topic;

@SpringBootApplication //一个注解顶下面3个
@EnableJms
public class MqApplication {


	/**
	 * 主题对象交给Spring管理，video.topic是主题的名称
	 * @return
	 */
	@Bean
	public Topic topic(){
		return new ActiveMQTopic("video.topic");
	}


	/**
	 * queue对象交给Spring管理，common.queue是队列的名称
	 * @return
	 */
	@Bean
	public Queue queue(){
		return new ActiveMQQueue("common.queue");
	}
	
	
	public static void main(String[] args) {
		SpringApplication.run(MqApplication.class, args);
	}


	/**
	 * 同时支持topic与queue，修改连接工厂
	 * @param activeMQConnectionFactory
	 * @return
	 */
	@Bean
	public JmsListenerContainerFactory<?> jmsListenerContainerTopic(ConnectionFactory activeMQConnectionFactory) {
		DefaultJmsListenerContainerFactory bean = new DefaultJmsListenerContainerFactory();
		bean.setPubSubDomain(true);
		bean.setConnectionFactory(activeMQConnectionFactory);
		return bean;
	}
	 
	
	
}
